package lambdda2;

import java.util.ArrayList;
import java.util.Comparator;

public class Test01 {
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(5);
        list.add(4);
        list.add(3);
        list.add(0);
        list.forEach(System.out::print);
        System.out.println();
        list.sort(Integer::compareTo);
        System.out.println("排序后：");
        list.forEach(System.out::print);
        list.sort(Comparator.reverseOrder());
        System.out.println("\n逆序：");
        list.forEach(System.out::print);
    }
    public static void main(String[] args) {

        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1, 18));
        list.add(new Student(2, 23));
        list.add(new Student(3, 20));
        list.add(new Student(11, 80));
        list.add(new Student(4, 19));
        list.add(new Student(5, 18));

        list.forEach(System.out::println);
        System.out.println("排序后：");
        list.sort(((o1, o2) -> o1.getAge() - o2.getAge()));//年龄升序
        list.forEach(System.out::println);
        list.removeIf(student -> student.getAge() > 60);
        System.out.println("删除大于60岁：");
        list.forEach(System.out::println);
        list.removeIf(s -> s.getId() == 1);
        System.out.println("删除id为1的：");
        list.forEach(System.out::println);
        /*
        输出结果：
                Student{id=1, age=18}
                Student{id=2, age=19}
                Student{id=3, age=20}
         */

    }
}
